package gov.fema.hazus.bdc.client.common.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FocusListener;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class TextBoxIntegerValueBlurHandler implements BlurHandler {

	@Override
	public void onBlur(BlurEvent event) {
		
		TextBox tb = (TextBox) event.getSource();
		try {
			Integer intValue = Integer.parseInt(tb.getText());
			Message.get().setText("");
			Message.get().hide();
			Message.get().removeInvalidField(tb.getName());
			tb.removeStyleName("validation-warning");
		} catch (NumberFormatException e) {
			tb.addStyleName("validation-warning");
			Message.get().addInvalidField(tb.getName());
			Message.get().setText("The "+tb.getName()+" field must be a valid number.");
			Message.get().show();
		}
	}
}
